package net.xdclass.controller;


import net.xdclass.controller.Request.LinkGroupAddRequest;
import net.xdclass.controller.Request.LinkGroupUpdateRequest;
import net.xdclass.enums.BizCodeEnum;
import net.xdclass.service.LinkGroupService;
import net.xdclass.util.JsonData;
import net.xdclass.vo.LinkGroupVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 二当家小D
 * @since 2025-08-15
 */
@RestController
@RequestMapping("/api/linkGroup/v1")
public class LinkGroupController {
	@Autowired
	private LinkGroupService linkGroupService;

	@PostMapping("/add")
	public JsonData addGroup(@RequestBody  LinkGroupAddRequest inkGroupAddRequest){
		int rows = linkGroupService.addGroup(inkGroupAddRequest);
		return rows == 1 ? JsonData.buildSuccess() : JsonData.buildResult(BizCodeEnum.GROUP_CREATE_FAIL);
	}

	@DeleteMapping("/del/{group_id}")
	public JsonData deleteGroup(@PathVariable("group_id") Long groupId){
		int rows = linkGroupService.delGroup(groupId);
		return rows == 1 ? JsonData.buildSuccess() : JsonData.buildResult(BizCodeEnum.GROUP_OPER_FAIL) ;
	}

	@GetMapping("/list")
	public JsonData getGroupList(){
		List list = linkGroupService.getList();
		return  JsonData.buildSuccess(list);
	}
	@GetMapping("/detail/{group_id}")
	public JsonData getDetail(@PathVariable("group_id") Long group_id ){
		 LinkGroupVO linkGroupVO = linkGroupService.getDetail(group_id);
		return  JsonData.buildSuccess(linkGroupVO);
	}
    @PutMapping("/update")
	public JsonData update(@RequestBody LinkGroupUpdateRequest request){
		int rows = linkGroupService.update(request);
		return rows == 1 ? JsonData.buildSuccess() : JsonData.buildResult(BizCodeEnum.GROUP_CREATE_FAIL);
	}
}

